package com.sq.shortlink.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sq.shortlink.admin.common.biz.user.UserContext;
import com.sq.shortlink.admin.common.convension.result.Result;
import com.sq.shortlink.admin.dao.entity.GroupDO;
import com.sq.shortlink.admin.dao.mapper.GroupMapper;
import com.sq.shortlink.admin.remoto.RecycleBinRemoteService;
import com.sq.shortlink.admin.remoto.dto.req.ShortLinkRecycleBinPageReqDTO;
import com.sq.shortlink.admin.remoto.dto.resp.ShortLinkPageRespDTO;
import com.sq.shortlink.admin.service.RecycleBinService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 回收站管理接口实现层
 * @author quan
 */
@Service
@RequiredArgsConstructor
public class RecycleBinServiceImpl implements RecycleBinService {

    private final GroupMapper groupMapper;

    private final RecycleBinRemoteService recycleBinRemoteService = new RecycleBinRemoteService() {
    };
    @Override
    public Result<IPage<ShortLinkPageRespDTO>> pageRecycleBinShortLink(ShortLinkRecycleBinPageReqDTO requestParam) {
        LambdaQueryWrapper<GroupDO> queryWrapper = Wrappers.lambdaQuery(GroupDO.class)
                .eq(GroupDO::getUsername, UserContext.getUsername())
                .eq(GroupDO::getDelFlag, 0);
        List<GroupDO> groupDOList = groupMapper.selectList(queryWrapper);
        requestParam.setGidList(groupDOList.stream().map(GroupDO::getGid).collect(Collectors.toList()));
        return recycleBinRemoteService.pageRecycleBinShortLink(requestParam);
    }
}
